<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>被测人管理</title>
<!-- 导入jquery核心类库 -->
<%@include file="../include/jqueryeasyui.jsp"%>

<script type="text/javascript">
	$(function() {

		main();

	});

	function main() {
		window.lMIDFenChang = GetQueryString('lMIDFenChang');
		initDatagrid();
		initBtn();
		initUploadWindow();
	}

	function GetQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null)
			return unescape(r[2]);
		return null;
	}

	function initDatagrid() {
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({
			visibility : "visible"
		});

		// 收派标准数据表格
		$('#grid').datagrid({
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			singleSelect : true,
			striped : true,
			toolbar : '#tb',
			url : "${pageContext.request.contextPath}/customer/page.list.ashx",
			queryParams : window.lMIDFenChang != null ? {
				'contractID' : window.lMIDFenChang
			} : new Object(),
			remoteSort : false,
			idField : 'id',
			columns : columns,
			pageList : [ 10, 50, 100, 200 ],
			pagination : true,
			view : myview,
			emptyMsg : "<font size=5>暂无记录</font>"

		});
	}

	function initBtn() {

		$('#search').click(doSearch);
		$('#downloadxls').click(doDownload);
		$('#uploadloadxls').click(doUpload);
	}

	function initUploadWindow() {
		//初始化销售员窗口
		$('#uploadWindow').window({
			title : '名单详情',
			width : 500,
			modal : true,
			shadow : true,
			closed : true,
			height : 200,
			resizable : true,
			modal : true

		});

	}

	function getQueryParams(queryParams) {
		var searchcontent = $('#searchcontent').val();

		var number = $('#number').val();

		queryParams.customerName = searchcontent;
		queryParams.customerIndex = number;
		return queryParams;

	}

	//增加查询参数，重新加载表格  
	function reloadgrid() {

		//查询参数直接添加在queryParams中      
		var queryParams = $('#grid').datagrid('options').queryParams;
		getQueryParams(queryParams);
		$('#grid').datagrid('options').queryParams = queryParams;
		$("#grid").datagrid('load');
	}

	function doSearch() {
		reloadgrid();
	}

	function doDownload() {

		location.href = "${pageContext.request.contextPath}/huamingce01.xls";
	}

	function doUpload() {

		$('#uploadWindow').form('clear');
		$('#uploadWindow *').trigger('blur');// 离焦
		$('#uploadWindow').window("open").window('setTitle', '上传Excel花名册');
		$("input[name='cid']").val('-1');
	}

	// 定义列
	var columns = [ [ {
		field : 'customerIndex',
		title : '编号',
		sortable : true,
		width : 60,

	}, {
		field : 'customerCom',
		title : '单位',
		width : 140,

	}, {
		field : 'customerDep',
		title : '部门',
		width : 60,
	}, {
		field : 'customerChildDep',
		title : '分部门',
		width : 60,
	}, {
		field : 'customerGroup',
		title : '班组',
		width : 60,
	}, {
		field : 'customerPost',
		title : '岗位',
		width : 60,
	}, {
		field : 'customerName',
		title : '姓名',
		width : 100,
	}, {
		field : 'customerSex',
		title : '性别',
		width : 30,
		formatter : formatterSex

	}, {
		field : 'customerDuty',
		title : '职务',
		width : 60,
	}, {
		field : 'customerTel',
		title : '电话',
		width : 100,
	}, {
		field : 'customerAge',
		title : '年龄',
		width : 30,
	}, {
		field : 'customerBeiZhu',
		title : '备注',
		width : 100,
	}, {
		field : 'v_fenchang',
		title : '所属分场',
		width : 140,
	}, {
		field : 'v_creatorName',
		title : '创建人',
		width : 100,
	}, {
		field : 'createTime',
		title : '创建时间',
		width : 100,
		formatter : formatterDate
	} ] ];

	function formatterId(value, row, index) {
		return "<a onclick=showDetails(" + index + ") href=#>详情</a>";
	}
	function showDetails(index) {
		$('#grid').datagrid('selectRow', index);// 关键在这里  
		var row = $('#grid').datagrid('getSelected');
		if (row) {
			location.href = "${pageContext.request.contextPath}/page.customerdetails.ashx?id="
					+ row.id;

		}
	}

	function formatterDate(value) {
		if (value == '' || null == value) {
			return '';
		}
		var now = new Date(value);
		var year = now.getYear() + 1900;
		var month = now.getMonth() + 1;
		var date = now.getDate();
		var hour = now.getHours();
		var minute = now.getMinutes();
		minute = (minute > 9) ? minute = minute : minute = '0' + minute;
		//var second=now.getSeconds(); 
		return year + "-" + month + "-" + date + " " + hour + ":" + minute;
	}

	function doFuQuan(index) {
		$('#grid').datagrid('selectRow', index);// 关键在这里  
		var row = $('#grid').datagrid('getSelected');

		if (row) {
			$.messager.alert("提示", "正在完善...", 'info');
		}
	}

	function formatterSex(value, row, index) {
		if (row.customerSex == 0) {
			return "男";
		} else if (row.customerSex == 1) {
			return "女";
		}
	}

	var myview = $.extend({}, $.fn.datagrid.defaults.view, {
		onAfterRender : function(target) {
			$.fn.datagrid.defaults.view.onAfterRender.call(this, target);
			var opts = $(target).datagrid('options');
			var vc = $(target).datagrid('getPanel').children(
					'div.datagrid-view');
			vc.children('div.datagrid-empty').remove();
			if (!$(target).datagrid('getRows').length) {
				var d = $('<div class="datagrid-empty"></div>').html(
						opts.emptyMsg || 'no records').appendTo(vc);
				d.css({
					position : 'absolute',
					left : 0,
					top : 50,
					width : '100%',
					textAlign : 'center'
				});
			}
		}
	});

	function uploadimg() {

		$("#sform")
				.ajaxSubmit(
						{

							type : "post", //提交方式    
							url : "${pageContext.request.contextPath}/page.uploadHuaMingCe.ashx", //请求url 
							success : function(data) { //提交成功的回调函数    
								if (data.status == 1) {
									$('#grid').datagrid('reload');
									$.messager.alert("提示", "上传成功！");
								}
								if (data.status == 0) {

									$.messager.alert("提示", data.msg);
									var file = $("#file");
									file.after(file.clone().val(""));
									file.remove();
								}

							},
							dataType : 'json'
						});
	}
</script>
</head>
<body class="easyui-layout">
	<div region="center">
		<table id="grid"></table>
	</div>

	<div id="tb" style="padding: 5px; height: auto">
		<div style="margin-bottom: 5px">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;编号: <input id="number"
				class="easyui-textbox" style="width: 100px">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;姓名: <input
				id="searchcontent" class="easyui-textbox" style="width: 100px">

			<!-- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;项目代号: <input id="pcode"  class="easyui-textbox" style="width:200px">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -->
			<a href="#" id="search" class="easyui-linkbutton"
				iconCls="icon-search">搜索</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<!-- <a href="#"  id="downloadxls" class="easyui-linkbutton" iconCls="icon-save">下载模板</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="#"  id="uploadloadxls" class="easyui-linkbutton" iconCls="icon-add">上传数据</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -->

		</div>
	</div>


	<div class="easyui-window" title="品类详情" id="uploadWindow"
		collapsible="false" minimizable="false" maximizable="false"
		style="top: 50px; left: 200px;">
		<div region="north" style="height: 31px; overflow: hidden;"
			split="false" border="false">
			<!-- <div class="datagrid-toolbar">
				<a id="close" icon="icon-cancel" href="#" class="easyui-linkbutton" plain="true" >关闭窗口</a>
			</div> -->
		</div>
		<div region="center" style="overflow: auto; padding: 5px;"
			border="false">
			<form id="sform" enctype="multipart/form-data"
				accept="application/excel, application/vnd.ms-excel,application/x-excel, application/x-msexcel">
				<table class="table-edit" width="80%" align="center">



					<tr>
						<td>Excel文件</td>
						<td><input onchange="uploadimg()"
							accept="application/excel, application/vnd.ms-excel,application/x-excel, application/x-msexcel"
							id="file" type="file" name="myfiles" /></td>
					</tr>
					<tr>
						<td colspan="2">*仅支持后缀为xls的Excel文件，点击"下载模板"按钮可下载花名册模板</td>
					</tr>



				</table>
			</form>
		</div>
	</div>
</body>
</html>